angular.module('app').controller('ngtableController', [ '$scope','$filter','$http','serverService','graphService','i18nService','dialogService','asciiTableService','codeEditorService','ngNotify','$compile','NgTableParams',function($scope,$filter,$http,serverService,graphService,i18nService,dialogService,asciiTableService,codeEditorService,ngNotify,$compile,NgTableParams) {

	$scope.users = [
        {name: "Moroni", age: 13},
        {name: "alis", age: 23},
        {name: "yldd", age: 33},
        {name: "zhang", age: 24},
        {name: "liuzh", age: 35},
        {name: "jianh", age: 38},
        {name: "zhiy", age: 39},
        {name: "hul", age: 25},
        {name: "zhout", age: 33},
        {name: "fud", age: 21},
        {name: "wangl", age: 29},
        {name: "nanr", age: 29},
        {name: "zhuh", age: 24},
        {name: "hongl", age: 30},
        {name: "Moroni", age: 3},
        {name: "Moroni", age: 3},
        {name: "Moroni", age: 3},
        {name: "Moroni", age: 3},
        {name: "Moroni", age: 3},
        {name: "Moroni", age: 3},
        {name: "Moroni", age: 3},
        {name: "Moroni", age: 3},
        {name: "Moroni", age: 3},
        {name: "Enos", age: 0}
    ];


    var ajaxData = $scope.users;

    $scope.customStaticConfigParams = createStaticUsingFullOptions();
    function createStaticUsingFullOptions() {
      var initialParams = {
        page: 1,
        count: 5 // initial page size
      };
      var initialSettings = {
        total: ajaxData.length,
        // page size buttons (right set of buttons in demo)
        counts: [5,10,15],
        // determines the pager buttons (left set of buttons in demo)
        paginationMaxBlocks: 13,
        paginationMinBlocks: 2,
        //dataset: $scope.backupdata
        getData: function (params) {
            console.log(ajaxData.length);
            $scope.results = params.sorting() ? $filter('orderBy')(ajaxData, params.orderBy()) : ajaxData;
            $scope.results = $scope.results.slice((params.page() - 1) * params.count(), params.page() * params.count());
            return $scope.results;
        }
      };
      return new NgTableParams(initialParams, initialSettings);
    }



    $scope.defaultConfigTableParams = new NgTableParams({}, { dataset: $scope.users});
    $scope.customConfigParams = createUsingFullOptions();

    function createUsingFullOptions() {
      var initialParams = {
        count: 5 // initial page size
      };
      var initialSettings = {
        // page size buttons (right set of buttons in demo)
        counts: [],
        // determines the pager buttons (left set of buttons in demo)
        paginationMaxBlocks: 13,
        paginationMinBlocks: 2,
        dataset: $scope.users
      };
      return new NgTableParams(initialParams, initialSettings);
    }

    $scope.cols = [
      { field: "name", title: "Name", sortable: "name", show: true },
      { field: "age", title: "Age", sortable: "age", show: true },
      { field: "money", title: "Money", show: true }
    ];
    //
    $scope.sortingConfigParams = new NgTableParams({
      // initial sort order
      sorting: { age: "desc" } 
    }, {
      dataset: $scope.users
    });
}]);